$(function() {
	var innerID;
	var parentInnerID=null;
	var url = ctxPath + "/sys/user/getUser.do";
	var data = {};
	doGetReq(url, data, function(rsp) {
		var retData = rsp.retData;
		innerID = retData.innerID;
		if(retData.parentInnerID != null) 
		{
			parentInnerID = retData.parentInnerID;
		}
		
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var dat = date.getDate();
		
		var hours = date.getHours();
		var minutes = date.getMinutes();
		var seconds = date.getSeconds();
		
		$('#orderDate').val(year + "-" + month + "-" +dat + " " + hours + ":" + minutes + ":" + seconds);
	});
	
//	$('#orderDate').datetimepicker({
//        format: "yyyy-mm-dd hh:ii:ss",
//        language: "zh-CN",
//        autoclose: true,
//        startView: 0,
//        maxView: 2
//    });
	
	$('#recordForm').bootstrapValidator({
		live : 'enabled',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields : {
			orderID : {
				validators : {
					notEmpty : {
						message : '订单号不能为空.'
					},
					stringLength : {
						max : 30,
						message : '必须在30字符长度之内.'
					},
					regexp : {
						regexp : /^[a-zA-Z0-9\-]+$/,
						message : '订单号只能由"数字"和"字母"、"-"组成.'
					},
					remote: {
						url: ctxPath + '/sys/order/checkOrder.do',
						message: '该订单号已经存在.'
					},
				}
			},
			asin : {
				validators : {
					notEmpty : {
						message : '订单号不能为空.'
					}
				}
			},
			orderPrice : {
				validators : {
					notEmpty : {
						message : '订单额不能为空.'
					},
					numeric : {
						message : '只能填写数字.'
					}
				}
			}
		}
	});
	
	$('#recordBtn').click(function() {
		$('#recordForm').data('bootstrapValidator').validate();
		if($("#recordForm").data('bootstrapValidator').isValid()) {
			var url = ctxPath + "/sys/order/saveOrder.do";
			var orderID = $("#orderID").val();
			var orderPrice = $("#orderPrice").val(); 
			var orderDate = $("#orderDate").val();
			var shopSite = "5";
			var label = $.cookie('ORDERINFO');
			var data = {"orderID": orderID, "label": label, "orderPrice": orderPrice, "orderDate": orderDate, "innerID": innerID, "shopSite": shopSite};
			if(parentInnerID != null) {
				data.parentInnerID = parentInnerID;
			}
			doPostReq(url, data, function(rsp) {
				$.cookie('ORDERINFO', '', {expires: -1});
				$('#recordForm').data('bootstrapValidator').resetForm(true);
				alert("登记成功");
			});
		}
    });
	
	$('#resetBtn').click(function() {
        $('#recordForm').data('bootstrapValidator').resetForm(true);
    });
});